﻿/**********************************************
 * 功能名称：接收操作员ID，返回操作员权限。
 *
 * 功能类型：AJAX
 * 功能摘要：与UserManagement.aspx  UserRightSetup.aspx两个页面相关。
 * 开发时间：2012-9-30 yangying
 * 
 **************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using CSM.Models;

namespace CSM.Views.Management
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

    //
    public class GetUserRight : IHttpHandler
    {
        CustomDataContext db = new CustomDataContext();
        public void ProcessRequest(HttpContext context)
        {
            //回调时触发AJAX
            string userid = HttpUtility.UrlDecode(System.Web.HttpContext.Current.Request.QueryString["id"]).ToString();
            //查询当前操作员的权限ID
            var query = (from a in db.TCsm_JS_User where a.UserID == userid select a).Single();
            string final = "";
            if (query.AllRightID != null)
            {
                string[] result = query.AllRightID.Split(',');
                foreach (string a in result)
                {
                    //获取权限ID对应的权限名称
                    var th = (from b in db.TCsm_JS_Menu where b.MenuID.ToString() == a select b.MenuName).Single();
                    final = final + th + "/";
                }
            }
            else
            {
                final = "未设置权限/";
            }

            context.Response.ContentType = "text/plain";
            context.Response.Write(final);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
